package com.atguigu.classroom.vod.service.impl;

import com.atguigu.classroom.model.vod.Video;
import com.atguigu.classroom.vod.mapper.VideoMapper;
import com.atguigu.classroom.vod.service.VideoService;
import com.atguigu.classroom.vod.utils.QiniuUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2022-07-10
 */
@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements VideoService {
    @Autowired
    private VideoMapper videoMapper;
    @Override
    public void removeVideo(Long id) {
        Video video = videoMapper.selectById(id);
        videoMapper.deleteById(id);
        List<String> fileKey=new ArrayList<>();
        if(video.getVideoSourceId()!=null){
            fileKey.add(video.getVideoSourceId());
            QiniuUtils.deleteFileList(fileKey);
        }
    }
}
